package elka.gis.postman.bean;

/**
 * Krawedz
 * @author Wojtek
 *
 */
public class Edge {
	private int length;
	private Vertex startPoint;
	private Vertex endPoint;

	public Edge() {
	}

	public Edge(Vertex startPoint, Vertex endPoint, int length) {
		this.startPoint = startPoint;
		this.endPoint = endPoint;
		this.length = length;
	}

	public int getLength() {
		return length;
	}

	public void setLength(int length) {
		this.length = length;
	}

	public Vertex getStartPoint() {
		return startPoint;
	}

	public void setStartPoint(Vertex startPoint) {
		this.startPoint = startPoint;
	}

	public Vertex getEndPoint() {
		return endPoint;
	}

	public void setEndPoint(Vertex endPoint) {
		this.endPoint = endPoint;
	}

	@Override
	public String toString() {
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder
				.append("Length: " + length + ",")
				.append(" V1: " + (startPoint != null ? startPoint.getId()
						: "null,"))
				.append(" V2: " + (endPoint != null ? endPoint.getId() : "null."));
		return stringBuilder.toString();

	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((endPoint == null) ? 0 : endPoint.hashCode());
		result = prime * result + length;
		result = prime * result
				+ ((startPoint == null) ? 0 : startPoint.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Edge other = (Edge) obj;
		if (endPoint == null) {
			if (other.endPoint != null)
				return false;
		} else if (!endPoint.equals(other.endPoint))
			return false;
		if (length != other.length)
			return false;
		if (startPoint == null) {
			if (other.startPoint != null)
				return false;
		} else if (!startPoint.equals(other.startPoint))
			return false;
		return true;
	}

}
